//
//  MainViewController.swift
//  LivingHelper
//
//  Created by Ampaw on 2017/9/8.
//  Copyright © 2017年 Ampaw. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    var homePageVC: AMPHomePageViewController!  // 主页
    var helperVC:   AMPHelperViewController!    // 助手
    var mineVC:     AMPMineViewController!      // 我

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupTabBarView()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated);
        
    }
    
    // MARK: 初始化TabBar
    func setupTabBarView(){
        
        var navc:UINavigationController!
        
        /**
         *  主页
         */
        if homePageVC == nil {
            homePageVC = AMPHomePageViewController()
            homePageVC.tabBarItem = UITabBarItem(title: "主页",
                                                 image: UIImage(named: "tab_home_normal")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal),
                                                 selectedImage: UIImage(named: "tab_home_select")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal))
            homePageVC.title = "主页"
            navc = UINavigationController(rootViewController: homePageVC)
            self.addChildViewController(navc)
        }

        /**
         *  助手
         */
         if helperVC == nil {
            helperVC = AMPHelperViewController()
            helperVC.tabBarItem = UITabBarItem(title: "助手",
                                               image: UIImage(named: "tab_helper_normal")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal),
                                               selectedImage: UIImage(named: "tab_helper_select")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal))
            helperVC.title = "助手"
            navc = UINavigationController(rootViewController: helperVC)
            self.addChildViewController(navc)
        }

        /**
         *  我
         */
        if mineVC == nil {
            mineVC = AMPMineViewController()
            mineVC.tabBarItem = UITabBarItem(title: "我",
                                             image: UIImage(named: "tab_me_normal")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal),
                                             selectedImage: UIImage(named: "tab_me_select")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal))
            mineVC.title = "我"
            navc = UINavigationController(rootViewController: mineVC)
            self.addChildViewController(navc)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
